/*
 * Copyright (c) 2018 Hitevision
 */

package tw.com.hitevision.whiteboard.android.state;

import android.content.Context;

import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import tw.com.hitevision.whiteboard.android.R;
import tw.com.hitevision.whiteboard.android.render.Line;
import tw.com.hitevision.whiteboard.android.render.Pen;

public class PenProperty extends LineProperty {
    @ColorInt
    private int color;

    private Size size;

    public PenProperty(@ColorInt int color, Size size) {
        this.color = color;
        this.size = size;
    }

    public void set(@ColorInt int c, Size s) {
        this.color = c;
        this.size = s;
    }

    public void setColor(@ColorInt int c) {
        color = c;
    }

    @ColorInt
    public int getColor() {
        return color;
    }

    public void setSize(Size s) {
        size = s;
    }

    public Size getSize() {
        return size;
    }

    @DrawableRes
    public int getStrokeRes() {
        switch (size) {
            case ONE:
                return R.drawable.ic_pen_stroke_1_4k;
            case TWO:
                return R.drawable.ic_pen_stroke_2_4k;
            case THREE:
                return R.drawable.ic_pen_stroke_3_4k;
            case FOUR:
                return R.drawable.ic_pen_stroke_4_4k;
            case FIVE:
                return R.drawable.ic_pen_stroke_5_4k;
            default:
                return 0;
        }
    }

    @DrawableRes
    public int getFloatingBarStrokeRes() {
        switch (size) {
            case ONE:
                return R.drawable.ic_pen_stroke_fb_1;
            case TWO:
                return R.drawable.ic_pen_stroke_fb_2;
            case THREE:
                return R.drawable.ic_pen_stroke_fb_3;
            case FOUR:
                return R.drawable.ic_pen_stroke_fb_4;
            case FIVE:
                return R.drawable.ic_pen_stroke_fb_5;
            default:
                return 0;
        }
    }


    @DrawableRes
    public int getOutlinedStrokeRes() {
        switch (size) {
            case ONE:
                return R.drawable.ic_pen_stroke_1_white_4k;
            case TWO:
                return R.drawable.ic_pen_stroke_2_white_4k;
            case THREE:
                return R.drawable.ic_pen_stroke_3_white_4k;
            case FOUR:
                return R.drawable.ic_pen_stroke_4_white_4k;
            case FIVE:
                return R.drawable.ic_pen_stroke_5_white_4k;
            default:
                return 0;
        }
    }

    @DrawableRes
    public int getFloatingBarOutlinedStrokeRes() {
        switch (size) {
            case ONE:
                return R.drawable.ic_pen_stroke_fb_1_white;
            case TWO:
                return R.drawable.ic_pen_stroke_fb_2_white;
            case THREE:
                return R.drawable.ic_pen_stroke_fb_3_white;
            case FOUR:
                return R.drawable.ic_pen_stroke_fb_4_white;
            case FIVE:
                return R.drawable.ic_pen_stroke_fb_5_white;
            default:
                return 0;
        }
    }

    public float getStrokeWidth() {
        switch (size) {
            case ONE:
                return 2.0f;
            case TWO:
                return 5.0f;
            case THREE:
                return 8.0f;
            case FOUR:
                return 13.0f;
            case FIVE:
                return 18.0f;
            default:
                return 0;
        }
    }

//    public Line create(Context context, float x, float y) {
//        final Line line = new Pen(context, x, y, getStrokeWidth());
//        line.setColor(color);
//        return line;
//    }

    /**
     * 细笔MOVE_CANVAS时同步笔迹粗细
     * @param context
     * @param x
     * @param y
     * @param canvasRatio
     * @return
     */
    public Line create(Context context, float x, float y, float canvasRatio) {
        if (0 == canvasRatio || Float.isNaN(canvasRatio) || Float.isInfinite(canvasRatio)) {
            canvasRatio = 1;
        }
        final Line line = new Pen(context, x, y, Math.max(getStrokeWidth() * canvasRatio, getStrokeWidth()));
        line.setColor(color);
        return line;
    }
}
